package com.heima.wemedia.controller.v1;


import com.heima.model.admin.dtos.SensitiveDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.wemedia.service.WmNewsAutoScanService;
import com.heima.wemedia.service.WmSensitiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;


@RestController
public class WmSensitiveController {

    @Autowired
    private WmSensitiveService wmSensitiveService;

    @Autowired
    private WmNewsAutoScanService autoScanService;

    /**
     * 查询敏感词列表
     * @param sensitiveDto 查询条件
     * @return
     */
    @PostMapping("/api/v1/sensitive/list")
    public ResponseResult list(@RequestBody SensitiveDto sensitiveDto){
        PageResponseResult result = wmSensitiveService.listSensitive(sensitiveDto);
        return result;
    }

    /**
     * 根据id删除
     * @param id id
     * @return
     */
    @DeleteMapping("/api/v1/sensitive/del/{id}")
    public ResponseResult delete(@PathVariable Integer id){
        return wmSensitiveService.delete(id);
    }


    /**
     * 保存
     * @param wmSensitive
     * @return
     */
    @PostMapping("/api/v1/sensitive/save")
    public ResponseResult save(@RequestBody WmSensitive wmSensitive){
        wmSensitive.setCreatedTime(new Date());
        wmSensitiveService.save(wmSensitive);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    /**
     * 保存
     * @param wmSensitive
     * @return
     */
    @PostMapping("/api/v1/sensitive/update")
    public ResponseResult update(@RequestBody WmSensitive wmSensitive){
        wmSensitive.setCreatedTime(new Date());
        wmSensitiveService.updateById(wmSensitive);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    /**
     * 查询所有敏感词
     * @return
     */
    @GetMapping("/api/v1/sensitive/findAll")
    public ResponseResult findAll(){
        List<WmSensitive> list = wmSensitiveService.list();
        return ResponseResult.okResult(list);
    }

}
